package kernel32

import (
	"syscall"
	"unsafe"
)



type (
	ATOM          uint16
	HANDLE        uintptr
	HGLOBAL       HANDLE
	HINSTANCE     HANDLE
	LCID          uint32
	LCTYPE        uint32
	LANGID        uint16
	HMODULE       uintptr
	HWINEVENTHOOK HANDLE
	HRSRC         uintptr
)


var (
	// Library.
	libkernel32 *syscall.LazyDLL

	// Functions.
	getModuleHandle     *syscall.LazyProc
	waitForSingleObject     *syscall.LazyProc
)

func init() {
	// Library.
	libkernel32 = syscall.NewLazyDLL("kernel32.dll")

	// Functions.
	getModuleHandle = libkernel32.NewProc("GetModuleHandleW")
	waitForSingleObject = libkernel32.NewProc("WaitForSingleObject")
}


func GetModuleHandle(lpModuleName *uint16) uintptr {
	ret, _, _ := syscall.Syscall(getModuleHandle.Addr(), 1,
		uintptr(unsafe.Pointer(lpModuleName)),
		0,
		0)

	return ret
}

func WaitForSingleObject(handle int, dwMilliseconds uint32) uintptr {
	ret, _, _ := syscall.Syscall(waitForSingleObject.Addr(), 2,
		uintptr(handle),
		uintptr(dwMilliseconds),
		0)

	return ret
}
